<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    body {
      margin: 0;
    }
    .bg {
      width: 100%;
      height: 400px;
      background: #fff;
      background-attachment: fixed;
    }
    .bg1 {
      background-image: url(./img/1.png);
    }
    .bg2 {
      background-image: url(./img/2.png);
    }
    .bg3 {
      background-image: url(./img/3.png);
    }
    .bg4 {
      background-image: url(./img/4.png);
    }
  </style>
</head>
<body>
  <div class="bg"></div>
  <div class="bg bg1"></div>
  <div class="bg"></div>
  <div class="bg bg2"></div>
  <div class="bg"></div>
  <div class="bg bg3"></div>
  <div class="bg"></div>
  <div class="bg bg4"></div>
  <div class="bg"></div>
  <script src="../libs/jquery-1.12.4.js"></script>
  <script>
    $(function () {
      var top = 0
      var y = 0
      $(document).on('scroll', function () {
        var _top = $(this).scrollTop() // 获取当前的滚动值
        
        if (_top > top) { // 和top进行比较
          y -= 1
          // console.log('向下')
        }else { 
          y += 1
          // console.log('向上')
        }
        $('.bg').css('backgroundPositionY', y)

        top = _top
      })

    })
  </script>
</body>
</html>